<template>
	<view>
		<view class="text-right padding-sm text-lg padding-top-lg" @tap="tocashlist">
			<text class="cuIcon-form text-green padding-right-xs"></text>
			提现记录
		</view>
		<view class="padding-sm">
			<view>账户余额提现</view>
			<view class="cu-form-group solids-bottom">
				<view class="title">¥</view>
				<input placeholder="输入提现金额" name="input" v-model="money"></input>
			</view>
			<view class="padding-top-xs">
				<text>可提现：<text class="text-red">¥{{balance}}</text></text>
				<text class="textright" @click="allWithDraw">全部提现</text>
			</view>
			<view style="height: 100rpx;"></view>
			<button class="cu-btn block bg-blue lg" @click="toCash">提现</button>
			<view class="padding-top-xl" style="color: #D8687A;">
				提示：接到微信通知，最近转账接口微信会增加限制，为方便客户能方便便捷提现，先关闭微信提现，请使用支付包或银行卡提现。
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				balance:0,
				money:'',
				type:""
			}
		},
		onLoad(options) {
			this.balance=options.balance;
			this.type=options.type
		},
		onShow() {},
		methods: {
			tocashlist() {
				uni.navigateTo({
					url:"/pages/toWithdrawal/cashList?type="+this.type
				})
			},
			allWithDraw(){
				this.money=this.balance
			},
			toCash(){
				if(!this.money){
					uni.showToast({
						icon: 'none',
					    title: '请输入提现金额'
					});
					return;
				}
				let that=this;
				that.http.tokenreq({
					url: 'user/v1/addwithdrawal',
					data: {
						"withdrawal_money":this.money,
						"withdrawal_type": this.type //字符串 提现类型  0  是 运营商 1 是代理商
					}
				}).then((res) => {
					let e=res.data;
					if(e.code==0 && e.success){
						uni.showModal({
							content: '提交成功',
							showCancel:false,
							success: function (res) {
								if (res.confirm) {
									uni.navigateTo({
										url:"/pages/toWithdrawal/cashList?type="+that.type
									})
								}
							}
						});
					}else{
						uni.showToast({
							icon: 'none',
						    title: e.message
						});
					}
				})
			}
		}
	}
</script>

<style>
	page{
		background-color: #FFFFFF;
	}
	.cu-form-group{
		padding: 0;
	}
	.textright{
		float: right;
	}
</style>
